/*
 * @Author: LVGRAPE
 * @LastEditors: LVGRAPE
 */
#include "at32f413.h"
#include "systick.h"
__IO uint32_t system_tick_ms = 0;
void systick_init(void)
{
    /* configure systick */
    systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV);
    SysTick_Config(SystemCoreClock / 1000);
}
uint32_t millis(void)
{
    return system_tick_ms;
}
uint32_t micros(void)
{
    return system_tick_ms * 1000;
}

void delay_ms(uint32_t ms)
{
    uint32_t start = millis();
    while (millis() < ms + start)
        ;
}
/**
 * @brief  this function handles systick handler.
 * @param  none
 * @retval none
 */
void SysTick_Handler(void)
{
    system_tick_ms++;
}
